//
// Created by zuo on 2024/7/4.
// 题目链接  https://www.lanqiao.cn/problems/191/learning/?page=1&first_category_id=1&problem_id=191
//

# include <bits/stdc++.h>

using namespace std;

bool f(int x)
{
    // 每次都 / 10
    while (x)
    {
        int y = x % 10;
        if (y == 2 || y == 0 || y == 1 || y == 9) return true;
        x /= 10; // 个位数除以 10 返回值为0
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++)
    {
        if (f(i)) sum += i;
    }
    cout << sum << endl;
    return 0;
}
